package com.csi.jf.crucible.opt.controller;

import java.io.IOException;

import com.chinasofti.ro.bizframework.core.mvc.Controller;
import com.chinasofti.ro.bizframework.core.mvc.View;
import com.chinasofti.ro.bizframework.core.orm.Page;
import com.chinasofti.ro.bizframework.core.orm.PageUtil;
import com.csi.jf.crucible.api.crucible.ApiTestReviews;
import com.csi.jf.crucible.ptservice.model.ServiceOrders;
import com.csi.jf.crucible.ptservice.service.ServiceOrdersService;
import com.icss.j2ee.util.http.HttpClientException;

/**
 * <p>controller</p>
 * 
 * @author BizFoundation
 * @version 1.0
 * @since 1.0
 */
public class OptController extends Controller {
	/**
	 * <p>显示列表</p>
	 * 
	 */
	public void showIndex() {
	    View view = new View(SUCCESS);
//	    List<ServiceOrders> ordersList=serviceOrdersService.getAllServiceOrders();
//	    JsonConfig config = new JsonConfig();
//	    config.registerJsonValueProcessor(java.sql.Timestamp.class,new TimestampJsonValueProcessor());
//	    String orders = JSONArray.fromObject(ordersList, config).toString();
//	    view.bind("serviceOrdersList", orders);
        this.render(view);
	}
	
	public void showServiceApply() {
        View view = new View(SUCCESS);
        this.render(view);
    }
	
	public void showOrders(String orderID) {
		
		
		
        View view = new View(SUCCESS);
        this.render(view);
    }
	
	public void showProfessors() {
        View view = new View(SUCCESS);
        this.render(view);
    }
	
	public void showComments() {
        View view = new View(SUCCESS);
        this.render(view);
    }
	
	/**
	 * 查找所有待审批（等分配专家）的服务订单
	 * @param page
	 * @param orders
	 */
	public void getTodoOrders(Page page,ServiceOrders orders){
	    serviceOrdersService.findByPage(orders, page);
	    this.renderJSON(PageUtil.toJson4JqGrid(page, true));
	}
	
	/**
     * 查找所有已审批（已分配专家）的服务订单
     * @param page
     * @param orders
     */
	public void getDoneOrders(Page page,ServiceOrders orders){
	    serviceOrdersService.findDoneOrdersByPage(orders, page);
        this.renderJSON(PageUtil.toJson4JqGrid(page, true));
    }
	
	/**
	 * 为订单分配专家
	 * @param orderId
	 * @throws IOException 
	 * @throws HttpClientException 
	 */
	public void allocateProfessor(Long orderId) throws HttpClientException, IOException{
	    serviceOrdersService.allocateProfessor(orderId);
	    ApiTestReviews testReviews=new ApiTestReviews();
	    String reviewId=serviceOrdersService.getReviewIdByOrId(orderId);
	    testReviews.addReviewers(reviewId,"maogx");
        this.renderJSON("{'result':'success'}");
	}
	
	 /**
     * <p>注入 pTSserviceService</p>
     */
    private ServiceOrdersService serviceOrdersService;

    public void setServiceOrdersService(ServiceOrdersService serviceOrdersService) {
        this.serviceOrdersService = serviceOrdersService;
    }
	
}